/********************************************************************************
* @author: Liu  HZ
* @date: 2024/9/9
* @description: 
********************************************************************************/

#ifndef THE_PATH_OF_CPP_VECTOR_ADD_OMP_H
#define THE_PATH_OF_CPP_VECTOR_ADD_OMP_H

#include <iostream>
#include <vector>
#include <omp.h>

struct MyStruct {
    int i = 0;
    std::string s;
};

MyStruct getStruct() {
    return MyStruct{42, "hello"};
}


// 向量加法
void vector_add_omp() {

    const int n = 10;
    std::vector<int> v1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<int> v2 = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
    std::vector<int> v3(n);

#pragma omp parallel for  default(none) shared(v1, v2, v3, n)
    for (int i = 0; i < n; ++i)
        v3[i] = v1[i] + v2[i];

    for (int i = 0; i < n; ++i)
        std::cout << v3[i] << " ";
    std::cout << std::endl;

}

void vector_dot_omp() {
    const int n = 10;
    std::vector<int> v1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    std::vector<int> v2 = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};

    int sum = 0;

#pragma omp parallel for default(none) shared(v1, v2, n) reduction(+:sum)
    for (int i = 0; i < n; ++i)
        sum -= v1[i] * v2[i];

    std::cout << sum << std::endl;
}

// 条件函数
bool condition(uint64_t value) {
    return value % 1000000 == 0; // 示例条件：值大于10
}


#endif //THE_PATH_OF_CPP_VECTOR_ADD_OMP_H
